<?php

class EnclosedList extends ResourceList
{

    //debo restringir la lista a un determinado proyecto

    protected $searchType;
    protected $searchText;
    public $milestoneToAttach;
    protected $project;

    function __construct()
    {
        parent::__construct( 'enclosed', $numperpage, '', $orders );
    }

    function setProject( $project )
    {
        $this->project = $project;
    }

    function setMilestoneToAttach( $milestone )
    {
        $this->milestoneToAttach = $milestone;
    }

    function setSearch( $type, $text )
    {
        $this->searchType = $type;
        $this->searchText = $text;
    }

    function handleGET( Event $e )
    {
        if ( $e->tag == 'seach' ) {

            $_GET[ 'search_text' ] = trim( preg_replace( '/\s+/', ' ',
                            $_GET[ 'search_text' ] ) );

            $type = null;
            if ( in_array( $_GET[ 'search_type' ], Enclosed::$TYPES ) )
                    $type = $_GET[ 'search_type' ];

            $this->_setSearch( $type, $_GET[ 'search_text' ] );

            $e->cancelBubble();
        }
    }

    function fill()
    {

        if ( !empty( $this->searchText ) ) {

            $partes = explode( ' ', $this->searchText );
            foreach ( $partes as &$p ) $p = MyLink::quote_lgr( $p, '%', '%' );

            $this->andWere( 'title LIKE ' . implode( ' OR title LIKE ', $partes ) );
        }

        if ( !empty( $this->searchType ) )
                $this->andWhere( 'type=\'' . $this->searchType . '\'' );

        parent::fill();
    }

    function doPOST( Event $e )
    {
        if ( $e->tag == 'delete_enclosed' ) $e->cancelBubble();
    }

}

?>
